package com.cart.controller;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.goodsColorClass.model.GoodsColorClassService;
import com.goodsColorClass.model.GoodsColorClassVO;

/**
 * Servlet implementation class ShowImg
 */
public class ShowImg extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		
		res.setHeader("Cache-Control","no-store"); //HTTP 1.1
		res.setHeader("Pragma","no-cache");        //HTTP 1.0
		res.setDateHeader ("Expires", 0);
		
		req.setCharacterEncoding("UTF-8");

		Integer goodsColorClassNo = Integer.parseInt(req.getParameter("picno"));
		
		GoodsColorClassService gccs = new GoodsColorClassService();
		GoodsColorClassVO gcc = gccs.getOneColorClass(goodsColorClassNo);
		
		ServletContext context = getServletContext();
		res.setContentType(context.getMimeType(gcc.getGoodsImgNameColor()));
		
		byte[] goodsPic = gcc.getGoodsImgSmall();
		
		ServletOutputStream sos = res.getOutputStream();
		
		sos.write(goodsPic);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
